#include<iostream>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>

#define ERR_EIXT(m)\
do{\
    perror(m);\
    exit(EXIT_FAILURE);\
}while(0)

int main(){
    if(mkfifo("myfifo",0644)<0)
        ERR_EIXT("making myfifo");
    
    int fifod=open("myfifo",O_RDWR);
    if(fifod<0)
        ERR_EIXT("opening myfifo");
    
    char buffer[1024];
    while(1){
         buffer[1024]={0};
        int s=read(fifod,buffer,sizeof(buffer)-1);
         if(!s){
            std::cout<<"Client quit!"<<std::endl;
            break;
        }
        else if(s>0){
            buffer[s]=0;
            std::cout<<"Client:"<<buffer<<std::endl;
        }
        else
            ERR_EIXT("read");
    }

    close(fifod);
    return 0;
}